package com.cuit.blog.entity;

import java.util.Date;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {
    //主键ID自动创建
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    
    // 创建时间
    @Temporal(TemporalType.TIMESTAMP) 
    @CreationTimestamp
    @Column(name="create_time", updatable=false)  //为防止手动set，设false以免该字段被更新
    private Date createTime;
    
    // 更新时间
    @Temporal(TemporalType.TIMESTAMP) 
    @UpdateTimestamp
    @Column(name="update_time", insertable=false)
    private Date updateTime;

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

	@Override
	public String toString() {
		return "BaseEntity [id=" + id + ", createTime=" + createTime + ", updateTime=" + updateTime + "]";
	} 
}
